import Editor from "../editor"
import { Operation } from "./baseOperation"
import RemoveTextOperation from "./removeTextOperation"
import SetSelectionOperation from "./setSelectionOperation"
export class InsertTextOperation extends Operation {
  public type: string = "InsertTextOperation"
  constructor(private spacers_: string, private insertIndex_: number) {
    super()
  }

  getspacers = () => {
    return this.spacers_
  }

  setSpacers = (spacers: string) => {
    this.spacers_ = spacers
  }

  apply(editor: Editor) {
    editor.getTextModel()?.insert(this.insertIndex_, this.spacers_)
  }

  reverse(): Operation[] {
    return [
      new RemoveTextOperation(
        this.insertIndex_,
        this.insertIndex_ + this.spacers_.length,
      ),
      new SetSelectionOperation({
        anchor: this.insertIndex_,
        focus: this.insertIndex_,
      }),
    ]
  }
}
export default InsertTextOperation
